package com.example.app.yidu.activity;

import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Toast;

import com.example.app.yidu.R;
import com.example.app.yidu.activity.utils.ToastUtil;

import static com.example.app.yidu.activity.utils.DataCleanManager.clearAllCache;
import static com.example.app.yidu.activity.utils.DataCleanManager.getTotalCacheSize;

public class SetActivity extends AppCompatActivity {
    private Toolbar toolbar;
    private AlertDialog dialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set);
        initView();
        initData();
    }

    private void initData() {
        toolbar.setTitle("设置");
        toolbar.setTitleTextColor(getResources().getColor(R.color.white));
    }

    private void initView() {
        toolbar= (Toolbar) findViewById(R.id.toolbar);
    }

    /**
     * 清理缓存
     * @param view
     */
    public void clickCrush(View view) {
        String size= null;
        try {
            size = getTotalCacheSize(getApplication());
        } catch (Exception e) {
            e.printStackTrace();
        }
        clearAllCache(getApplication());
        ToastUtil.toast(getApplication(),"清理缓存："+size+"^_^");
    }

    /**
     * 退出登录
     */
    public void exit(View view) {

    }

    /**
     * 关于
     */
    public void about(View view) {
        dialog = new AlertDialog.Builder(this).create();
        dialog.show();
        Window window = dialog.getWindow();
        // *** 主要就是在这里实现这种效果的.
        // 设置窗口的内容页面,shrew_exit_dialog.xml文件中定义view内容
        window.setContentView(R.layout.about_app);
    }
}
